/*
 * Copyright (c) 2008 Benoit Bouchez, Nicolas Giard
 * 
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */
package com.noocodecommit.wicket.stuff.jquery.plugin.ui.sortable;

import java.io.Serializable;

import com.noocodecommit.wicket.stuff.jquery.JQCore;
import com.noocodecommit.wicket.stuff.jquery.plugin.JQPlugin;
import com.noocodecommit.wicket.stuff.jquery.plugin.ui.core.JQUiCorePlugin;

/**
 * JQuery Sortable plugin
 * 
 * @author Benoit Bouchez
 * 
 */
public class JQSortablePlugin extends JQPlugin implements Serializable
{
	/** JQuery plugin default key */
	public static final String DEFAULT_KEY = "ui.sortable";

	/** JQuery sortable default options */
	private JQSortableOptions options = new JQSortableOptions();

	/**
	 * Constructor
	 * 
	 * @param key :
	 *            plugin unique id
	 */
	public JQSortablePlugin(String key)
	{
		super(key);
		// -- Dependency ui.base
		this.addDependency(new JQUiCorePlugin());
		// -- Library ui.sortable
		this.addJavascriptResource(JQSortablePlugin.class, "lib/ui.sortable" + JQCore.getLibraryMode() + ".js", "lib/ui.sortable" + JQCore.LIBMODE_STANDARD + ".js");
		// -- Bind to JQuery Core
		JQCore.get().bindPlugin(this);
	}

	/**
	 * Constructor
	 */
	public JQSortablePlugin()
	{
		this(DEFAULT_KEY);
	}

	/**
	 * Gets plugin options used when plugin initMode is PLUGIN_INIT_MODE_ONCE
	 * 
	 * @return plugin options
	 */
	public JQSortableOptions getOptions()
	{
		return options;
	}

	/**
	 * Set plugin option used when plugin initMode is PLUGIN_INIT_ONCE
	 * 
	 * @param options
	 *            plugin options
	 */
	public void setOptions(JQSortableOptions options)
	{
		this.options = options;
	}

	@Override
	public String getPluginReadyScript()
	{
		return "$('" + this.getInitOnceSelector() + "')." + this.options.getDocumentReadyOptions();
	}
}
